home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / scrsav4.zip / SCRSAV.PAS < prev    next >
Pascal/Delphi Source File  |  1994-04-10  |  22KB  |  642 lines

  1. {
  2.         SCRSAV.PAS - A ScreenSaving unit (version 4) for TurboVision 2.0
  3.  
  4.  
  5.         This ScreenSaving-unit for TurboVision 2.0 is (c) by Edwin Groothuis
  6.         You are allowed to use this unit in your programs if you agree to
  7.         these two rules:
  8.  
  9.         1. You give me proper credit in the documentation of the program.
  10.         2. You tell me you're using this unit.
  11.  
  12.         If you don't agree with these two rules, you're not allowed to
  13.         use it!
  14.  
  15.         How to use this ScreenSaving-unit:
  16.  
  17.         Initialisation:
  18.  
  19.         - Add the ScrSav-unit to the uses-command.
  20.         - Make the (global) variable ScreenSaver as PScreenSaver
  21.         - In the Initialisation of an Application, put the following
  22.           line behind the Inherited Init:
  23.             Inherited Init;
  24.             ScreenSaver:=New(PScreenSaver,Init(MakeStandardScreenSaver,6));
  25.  
  26.         Heartbeat:
  27.         To tell the ScreenSaver that the user isn't idle at this moment,
  28.         put the following line in the Application^.GetEvent:
  29.           Inherited GetEvent(E);
  30.           if E.What<>evNothing then
  31.             if ScreenSaver<>nil then
  32.               if E.What=evKeyDown then
  33.               begin
  34.                 if ScreenSaver^.Saving then
  35.                   E.What:=evNothing;
  36.                 ScreenSaver^.HeartBeat;
  37.               end else
  38.                 if E.What and evMouse<>0 then
  39.                   ScreenSaver^.HeartBeat;
  40.  
  41.         CountDown:
  42.         To let the ScreenSaver know the user is idle at this moment, put
  43.         the following line in the Application^.Idle:
  44.           Inherited Idle;
  45.           if ScreenSaver<>nil then
  46.             ScreenSaver^.CountDown;
  47.  
  48.         Options:
  49.         What is a ScreenSaver without options? You can change the
  50.         options by calling the ScreenSaver^.Options-procedure. The user
  51.         gets a nice options-dialog and he can change some settings. If
  52.         you have added more ScreenSaver-modules, please add them in the
  53.         constants ScreenSaverNames and ScreenSaverProcs. Make sure you
  54.         put them in alphabetic order!
  55.  
  56.  
  57.         Now start your application. After 6 seconds your screen will
  58.         go blank. There are several ScreenSavers designed by me, if
  59.         you have created more, I would like to have a copy of them ;-)
  60.  
  61.         A small note about the use of a delay in the ScreenSaver^.Update:
  62.         It's not nice to use the Delay-function of the Crt-unit. Instead
  63.         of using that, you'd better check if a certain time (100 ms, 200 ms
  64.         and so on) has elapsed. See the StarFieldScreenSaver.Update-function
  65.         for an example of it.
  66.  
  67.         Send all your suggestions/money/cards (I love to get cards from
  68.         people who are using my programs) to:
  69.  
  70.         Edwin Groothuis                ECA-BBS
  71.         Johann Strausslaan 1           tel. +31-40-550352 (up to 14k4/V42b)
  72.         5583ZA Aalst-Waalre            FTN: 2:284/205@fidonet
  73.         The Netherlands                     115:3145/102@pascal-net
  74.                                        request SCRSAV for the last version!
  75. }
  76.  
  77.  
  78. unit      ScrSav;
  79.  
  80. interface
  81.  
  82. uses      Views,Objects;
  83.  
  84. type      PScreenSaver=^TScreenSaver;
  85.           TScreenSaver=object
  86.                          constructor Init(_W:PView;Time:word);
  87.                          destructor Done;
  88.                          procedure Activate;
  89.                          procedure Deactivate;
  90.                          procedure HeartBeat;
  91.                          procedure CountDown;
  92.                          procedure Update;virtual;
  93.                          function  Saving:boolean;
  94.                          procedure Options;
  95.                          procedure Enable(b:boolean);
  96.                        private
  97.                          W:PView;
  98.                          LastBeat:longint;
  99.                          _Saving:boolean;
  100.                          SavedScreen:pointer;
  101.                          SavingTime:word;
  102.                          CursorVisible:boolean;
  103.                          Enabled:boolean;
  104.                          Testing:boolean;
  105.                        end;
  106.  
  107.  
  108. type      PStandardScreenSaver=^TStandardScreenSaver;
  109.           TStandardScreenSaver=object(TView)
  110.                                  constructor Init;
  111.                                  procedure Draw;virtual;
  112.                                end;
  113.  
  114.  
  115. function  MakeStandardScreenSaver  :PStandardScreenSaver;
  116. function  MakeMovingStarScreenSaver:PStandardScreenSaver;
  117. function  MakeWormScreenSaver      :PStandardScreenSaver;
  118. function  MakeStarFieldScreenSaver :PStandardScreenSaver;
  119.  
  120.  
  121. implementation
  122.  
  123. uses      Drivers,App,Dialogs,InpLong;
  124.  
  125. const     NumScreenSavers=4;
  126. const     ScreenSaverNames:array[0..NumScreenSavers-1] of string[20]=
  127.                             (
  128.                              'Moving Star',
  129.                              'Standard',
  130.                              'Starfield',
  131.                              'Worm'
  132.                              );
  133.           ScreenSaverProcs:array[0..NumScreenSavers-1] of function:
  134.                             PStandardScreenSaver=(
  135.                                                   MakeMovingStarScreenSaver,
  136.                                                   MakeStandardScreenSaver,
  137.                                                   MakeStarfieldScreenSaver,
  138.                                                   MakeWormScreenSaver
  139.                                                   );
  140.  
  141. const     cmTest=1000;
  142.  
  143. {----------------------------------------------------------------------------}
  144. { Object-definitions of the screensave-routines. Note that these are not the
  145.   screensaverobject!                                                         }
  146. type      PMovingStarScreenSaver=^TMovingStarScreenSaver;
  147.           TMovingStarScreenSaver=object(TStandardScreenSaver)
  148.                                    constructor Init;
  149.                                    procedure Draw;virtual;
  150.                                  private
  151.                                    dx,dy,x,y:array[1..10] of integer;
  152.                                    LastUpdate:longint;
  153.                                  end;
  154.  
  155.           PWormScreenSaver=^TWormScreenSaver;
  156.           TWormScreenSaver=object(TStandardScreenSaver)
  157.                              constructor Init;
  158.                              procedure Draw;virtual;
  159.                            private
  160.                              x,y:array[1..10] of integer;
  161.                              states:array[1..10] of char;
  162.                              dx,dy:integer;
  163.                              LastUpdate:longint;
  164.                            end;
  165.  
  166.           PStarFieldScreenSaver=^TStarFieldScreenSaver;
  167.           TStarFieldScreenSaver=object(TStandardScreenSaver)
  168.                                    constructor Init;
  169.                                    procedure Draw;virtual;
  170.                                  private
  171.                                    states:array[1..7] of char;
  172.                                    starstate,x,y:array[1..10] of integer;
  173.                                    LastUpdate:longint;
  174.                                  end;
  175.  
  176. {----------------------------------------------------------------------------}
  177. { Object-definition of the screensaver                                       }
  178. type      PScrSavDialog=^TScrSavDialog;
  179.           TScrSavDialog=object(TDialog)
  180.                           UserSavingTime:PInputLine;
  181.                           LB:PListBox;
  182.                           TestButton:PButton;
  183.                           Timer:PRadioButtons;
  184.  
  185.                           procedure HandleEvent(var E:TEvent);virtual;
  186.                         end;
  187.  
  188. var       CurrentScreenSaver:PScreenSaver;
  189.  
  190. {----------------------------------------------------------------------------}
  191. {----------------------------------------------------------------------------}
  192. { Initialise the ScreenSaver.
  193.   Notes:
  194.     *18.2 is because the timertick goes 18.2 times/second                    }
  195. constructor TScreenSaver.Init(_W:PView;Time:word);
  196. begin
  197.   _Saving:=fals